package com.xjtlu.manager.exception;

import com.xjtlu.manager.response.Result;
import com.xjtlu.manager.response.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Classname GlobalExceptionHandler
 * @Description TODO
 * @Date 2022/4/4 19:48
 * @Created by jisf：【429627912@qq.com】
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理HotelManager异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(HotelManagerException.class)
    public Result<?> resolveDrivingSchoolException(HotelManagerException e) {
        log.error(e.getMessage(), e.getE());
        return Result.error(e.getCode(), e.getMessage());
    }

    /**
     * 处理其他异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result<?> resolveException(Exception e) {
        e.printStackTrace();
        return Result.error(ResultCode.SYSTEM_FAILED);
    }

}
